//
//  SPSlidingCell.m
//  QADoctor
//
//  Created by 陈飞宇 on 17/3/31.
//  Copyright © 2017年 Spencer. All rights reserved.
//

#import "SPSlidingCell.h"
#import "LZLoginViewController.h"
#import "AppDelegate.h"
#import "JNavigationController.h"
#define CFYUserDefaults [NSUserDefaults standardUserDefaults]
@interface SPSlidingCell ()

@property (nonatomic, weak) UIImageView *imageView;

@property (nonatomic, weak) UIButton *startButton;
@end

@implementation SPSlidingCell

- (UIButton *)startButton
{
    if (_startButton == nil) {
        UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [startBtn setTitle:@"开始体验" forState:UIControlStateNormal];
        [startBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [startBtn sizeToFit];
        startBtn.layer.borderWidth = 1;
        startBtn.layer.borderColor = [UIColor greenColor].CGColor;
        [startBtn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
        startBtn.backgroundColor = [UIColor clearColor];
        [self addSubview:startBtn];
        _startButton = startBtn;
        
        
    }
    return _startButton;
}

- (UIImageView *)imageView
{
    if (_imageView == nil) {
        
        UIImageView *imageV = [[UIImageView alloc] init];
        
        _imageView = imageV;
        
        // 注意:一定要加载contentView
        [self.contentView addSubview:imageV];
        
    }
    return _imageView;
}

// 布局子控件的frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.frame = self.bounds;
    
    // 开始按钮
    self.startButton.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.8);
}

- (void)setNameStr:(NSString *)nameStr
{
    _nameStr = nameStr;
    NSLog(@"name---%@",nameStr);
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:nameStr]];

}
// 判断当前cell是否是最后一页
- (void)setIndexPath:(NSIndexPath *)indexPath count:(NSInteger )count
{
    if (indexPath.row == count - 1) { // 最后一页,显示分享和开始按钮
        self.startButton.hidden = NO;
        
        
    }else{ // 非最后一页，隐藏分享和开始按钮
        self.startButton.hidden = YES;
    }
}

- (void)start
{
    NSLog(@"点击----");
    
    [CFYUserDefaults setBool:YES forKey:@"isFirst"];
    [CFYUserDefaults synchronize];
    
    AppDelegate *delegate =(AppDelegate *)[UIApplication sharedApplication].delegate;

    LZLoginViewController *loginVc = [[LZLoginViewController alloc]init];
    JNavigationController *nav = [[JNavigationController alloc]initWithRootViewController:loginVc];
    delegate.window.rootViewController = nav;
    
}

@end
